package cn.io1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo01 {
    public static void main(String[] args) {
        // demo01();
        // demo02();
        demo03();
    }

    private static void demo03() {
        try (
            FileInputStream fis = new FileInputStream("move/001.jpg");
            FileOutputStream fos = new FileOutputStream("move/002.jpg")
        ){
            byte[] bytes = new byte[1024];
            int len;
            while ((len=fis.read(bytes))!=-1){
                fos.write(bytes,0,len);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    private static void demo02() {
        try (FileInputStream fis = new FileInputStream("move/mm.log")){
            byte[] bytes = new byte[1024];
            int b;
            while ((b=fis.read(bytes))!=-1){
                System.out.println(new String(bytes,0,b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void demo01() {
        try (FileOutputStream fos = new FileOutputStream("move/mm.log",true)){
            fos.write("\n吊毛，laotie,666".getBytes());
            System.out.println("ok");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
